<?php
/**
 * 	合同管理模板
 *  author： chengda
 *  date  ： 2017-11-22
 */
namespace Admin\Controller;

class BillController extends AbstractController  {

	protected $From;

	public function _initialize(){
		$this->Form = D('bill');
    }
	

    public function index(){
	    $res = $this->Form->MyshowList();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
        $this->display();
    }


    public function save($type = false, $id = 0){
    	
			//$this->assign("data", $this->Form->GetCatalog());
			$this->display();
		
    }

    public function edit(){
    	if(I('ID')){
			$res = $this->Form->Myshow((int)I('ID'));
			$this->assign("editdata",$res);
		}
		$this->display("save");
    }

    public function add(){
		$_POST['AddTime']=date('Y-m-d H:i:s',time());
		//1查询这个合同所有支持金额
		//2判断金额是否超额
		$ID=$_POST['ContractID'];
		$res=$this->Form->operation($ID,I('Bill'));
		if($res['state']==1){
			if(!$this->Form->create()){
			exit($this->error($this->Form->getError()));
			}else{
			$result = $this->Form->add();
			if($result){
			$this->success('添加成功！');
			}else{
			$this->error('添加错误！');
			}
			}
		  }else{
			$this->error('添加金额超额');
		}
		
    }

    public function delete(){
    	$res = $this->Form->MydeletP();
    	if($res['state']){
			$this->success($res['msg']);
		}else{
			$this->error($res['msg']);
		}
    }

    public function update(){
		$result = $this->Form->Myupdata();
		//var_dump($result); exit();
		if($result['status'] == 1 && !empty($result)){
			$this->success($result['msg']);
		}else if($result['status'] == 0 && !empty($result)){
			$this->error($result['msg']);
		}
    }
   


}